<template>
  <div class="parkPictureWrap" ref="parkPictureWrap">
    <div class="pageTableInner">
      <div class="infoSearchWrap">
        <div class="infoSearchOne">
          <el-row :gutter="20">
            <!-- <el-col :span="7">
              <div class="searchWrap">
                <span class="searchFont">行政区域:</span>
                <span class="searchInputFont" style="width: 38%;">
                  <el-select :disabled="$store.state.userInfo.regionId?true:false" v-model="searchInfo.district" @change="changeDistrict(searchInfo.district)" size="mini"
                             clearable placeholder="行政区">
                    <el-option
                      v-for="item in $store.state.districtData"
                      :key="item.id"
                      :label="item.regionName"
                      :value="item.id">
                    </el-option>
                  </el-select>
                </span>
                <span class="searchInputFont" style="width: 38%;">
                    <el-select v-model="searchInfo.street" @change="checkstreet" size="mini" clearable placeholder="街道">
                      <el-option
                        v-for="item in streetData"
                        :key="item.id"
                        :label="item.regionName"
                        :value="item.id">
                      </el-option>
                    </el-select>
                 </span>
              </div>
            </el-col> -->
            <!-- <el-col :span="5">
              <div class="searchWrap">
                <span class="searchFont">区域名称:</span>
                <span class="searchInputFont">
                    <el-input clearable size="mini" v-model="searchInfo.areaName" @change="selectGovAreaMap()" auto-complete="off" placeholder="区域名称"></el-input>
                </span>
              </div>
            </el-col> -->
            <el-col :span="9">
              <div class="searchWrap">
                <span class="searchFont">区域类型:</span>
                <span class="searchInputFont">
                   <el-radio-group size="mini" v-model="searchInfo.type" @change="selectGovAreaMap()">
                    <el-radio-button v-for="(item,index) in typeList" :key="index" :label="item.value">{{item.label}}</el-radio-button>
                  </el-radio-group>
                </span>
              </div>
            </el-col>

            <div style="float: right;margin-right: 10px;">
              <el-button type="primary" size="mini" @click="selectGovAreaMap()">查询</el-button>
            </div>
          </el-row>
        </div>
      </div>
      <div class="mapContentWrap">
        <mapBicycletest
          :areaInfo="areaInfo"
          :colorslist="colorslist"
          :district="searchInfo.district"
          ref="mapFun"
          @selectGovAreaMap="selectGovAreaMap"
        ></mapBicycletest>

      </div>
    </div>
  </div>
</template>
<script>
  import mapBicycletest from "./mapRack.vue"

  export default {
    props: [],
    data(){
      return {
        searchInfo: {
          areaName: "",
          type: "",
          district: 1,//this.$store.state.userInfo.regionId,
          street: 13,
          areaStatus: 0,
        },
        streetData: [],
        typeList: [
          {label: "全部", value: ""},
          {label: "停放区", value: 0},
          {label: "监控区", value: 1},
          {label: "电子围栏", value: 2},
          {label: "禁停区", value: 3},
        ],
        colorslist: [{
          color: '#00a436',
          label: '停放区',
          areaType: 0,
          count: '0'
        },{
          color: '#00b2ed',
          label: '监控区',
          areaType: 1,
          count: '0'
        },{
          color: '#567aff',
          label: '电子围栏',
          areaType: 2,
          count: '0'
        },{
          color: '#ff5656',
          label: '禁停区',
          areaType: 3,
          count: '0'
        }/*, {
          src: "./images/Intelligent.png",
          label: '智能站点',
          areaType: 0,
          count: '0'
        }*/],
        areaInfo:[[],[],[],[],[]]
      }
    },
    components: {
      mapBicycletest
    },
    created(){
      // 获取首次数据
      this.selectGovAreaMap()
      this.changeDistrict(this.searchInfo.district)
      /*setTimeout(()=>{
        if(this.$store.state.userInfo.regionId){
          this.changeDistrict(this.searchInfo.district)
        }
      },500)*/
    },
    destroyed(){

    },
    methods: {
      //改变行政区 获取街道
      changeDistrict(district){
        // this.selectGovAreaMap()
        // this.searchInfo.street=""
        if(!district){
          this.streetData=[]
          return
        }
        this.axios.post(process.env.API_HOST + '/common/selectRegion', {parentId: district})
          .then(response => {
            const result = response.data
            if (result.code == 200) {
              this.streetData = result.result
              this.checkstreet()
            }
          })

        //定到区域
        /*this.$store.state.districtData.forEach(item => {
          if (item.id == district && item.regionPoints) {
            setTimeout(()=>{
              this.$refs.mapFun.getBoundary(JSON.parse(item.regionPoints))
            },100)
          }
        })*/
      },
      //改变街道
      checkstreet(){
        // this.selectGovAreaMap()
        if(!this.searchInfo.street){
          this.changeDistrict(this.searchInfo.district)
        }
        this.streetData.forEach(item => {
          if (item.id == this.searchInfo.street && item.regionPoints) {
            setTimeout(()=>{
              this.$refs.mapFun.getBoundary(JSON.parse(item.regionPoints))
            },100)
          }
        })
      },
      selectGovAreaMap(){
        this.axios.post(process.env.API_HOST + `/facilities/selectFacilitiesMap`,this.searchInfo)
          .then(response => {
            const result = response.data
            if (result.code == 200) {
              this.areaInfo=[[],[],[],[],[]]
              if (result.result.length > 0) {
                result.result.forEach((item) => {
                  this.areaInfo[item.type].push({
                    ...item,
                    areaPoints: item.areaPoints ? JSON.parse(item.areaPoints) : []
                  })
                })
              }
              this.colorslist.forEach(item => {
                item.count = this.areaInfo[item.areaType].length
              })
              console.log(this.colorslist)
              this.checkstreet()
            }
          })
      },

    }
  }
</script>


<style lang="stylus" rel="stylesheet/stylus">
  @import "../../../common/stylus/mixin.styl"
  .parkPictureWrap
    page()
    .mapContentWrap
      position absolute;
      left 0px;
      right 0px
      bottom 0px
      top 78px
      padding: 10px;
      box-sizing: border-box;
      border-radius: 5px;
      background-color: white;
</style>
